package com.swz.dcrm.ui.main;

import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.View;

import com.swz.dcrm.R;
import com.swz.dcrm.adpter.FragmentViewPagerAdapter;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.ui.viewmodel.MainViewModel;
import com.xh.baselibrary.widget.NoScrollViewPager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

public class MainFragment extends BaseFragment {


    @BindView(R.id.view_pager)
    NoScrollViewPager mViewPager;

    @Inject
    MainViewModel mainViewModel;

    private List<Fragment> fragments;
    private String[] titles=new String[]{};

    public static MainFragment newInstance() {
        return new MainFragment();
    }


    @Override
    public void onLoadRetry() {

    }


    @Override
    public int layoutId() {
        return R.layout.main_fragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        changeStatusBarColor(false);
        onLoadRetry();

        mainViewModel.getShowTab().setValue(true);
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        fragments=new ArrayList<>();
        fragments.add(HomeFragment.getInstance());
        fragments.add(MessageFragment.getInstance());
        fragments.add(MineFragment.getInstance());
        mViewPager.setOffscreenPageLimit(3);
        mViewPager.setAdapter(new FragmentViewPagerAdapter(getActivity().getSupportFragmentManager(),fragments, Arrays.asList(titles)));
        mainViewModel.getPageIndex().observe(this,integer -> mViewPager.setCurrentItem(integer));
       // changeStatusBarTextColor(true);
        return false;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }


}
